package br.com.slsystems.travianbot.action;
import java.util.Observable;
import java.util.Observer;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;
import br.com.slsystems.travianbot.view.ICommandIds;
import br.com.slsystems.travianbot.view.LoginDialog;

public class OpenLoginDialogAction extends Action implements Observer  {

    private final IWorkbenchWindow window;

    OpenLoginDialogAction(String text, IWorkbenchWindow window) {
        super(text);
        this.window = window;
        setId(ICommandIds.CMD_OPEN_LOGIN_DIALOG);
        setActionDefinitionId(ICommandIds.CMD_OPEN_LOGIN_DIALOG);
        setImageDescriptor(br.com.slsystems.travianbot.Activator.getImageDescriptor("/icons/sample3.gif"));
    }

    public void run() {
    	LoginDialog loginDialog = new LoginDialog(window.getShell());
    	loginDialog.addObserver(this);
    }

	@Override
	public void update(Observable o, Object arg) {
		if(o instanceof LoginDialog) {
			if(arg instanceof String) {
				System.out.println("Retornado via Update: " + (String) arg);
			}
		}		
	}
}